<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>ansi (Table)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File ansi.rb, line 85</span>
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">ansi</span> <span class="ruby-identifier">format</span>=<span class="ruby-keyword kw">nil</span>,<span class="ruby-operator">*</span><span class="ruby-identifier">opts</span>
  <span class="ruby-identifier">code</span> = []
  <span class="ruby-identifier">excel</span> = []
<span class="ruby-comment cmt"># p opts;exit</span>
  <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">o</span>
      <span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/clear/</span>
        <span class="ruby-identifier">code</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\e[0m&quot;</span> 
        <span class="ruby-comment cmt"># reset; clears all colors and styles (to white on black)</span>
      <span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/bold/</span>
        <span class="ruby-identifier">code</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\e[1m&quot;</span>
        <span class="ruby-identifier">excel</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;:weight =&gt; :bold&quot;</span>
        <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">format</span>
          <span class="ruby-identifier">format</span>.<span class="ruby-identifier">font</span>.<span class="ruby-identifier">bold</span>=<span class="ruby-keyword kw">true</span>
        <span class="ruby-keyword kw">end</span>
        <span class="ruby-comment cmt"># bold on (see below)</span>
      <span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/italic/</span>
        <span class="ruby-identifier">code</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\e[3m&quot;</span> 
        <span class="ruby-identifier">excel</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;:italic =&gt; true&quot;</span>
        <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">format</span>
          <span class="ruby-identifier">format</span>.<span class="ruby-identifier">font</span>.<span class="ruby-identifier">italic</span>=<span class="ruby-keyword kw">true</span>
        <span class="ruby-keyword kw">end</span>
        <span class="ruby-comment cmt"># italics on</span>
      <span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/underline/</span>
        <span class="ruby-identifier">code</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\e[4m&quot;</span>
        <span class="ruby-identifier">excel</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;:underline =&gt; true&quot;</span>
        <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">format</span>
          <span class="ruby-identifier">format</span>.<span class="ruby-identifier">font</span>.<span class="ruby-identifier">underline</span>=<span class="ruby-keyword kw">true</span>
        <span class="ruby-keyword kw">end</span>
        <span class="ruby-comment cmt"># underline on</span>
      <span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/inverse/</span>
        <span class="ruby-identifier">code</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\e[7m&quot;</span>
        <span class="ruby-comment cmt"># inverse on; reverses foreground &amp; background colors</span>
      <span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/strike/</span>
        <span class="ruby-identifier">code</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\e[9m&quot;</span>
        <span class="ruby-identifier">excel</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;:strikeout =&gt; true&quot;</span>
        <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">format</span>
          <span class="ruby-identifier">format</span>.<span class="ruby-identifier">font</span>.<span class="ruby-identifier">strikeout</span>=<span class="ruby-keyword kw">true</span>
        <span class="ruby-keyword kw">end</span>
        <span class="ruby-comment cmt"># strikethrough on</span>
     <span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/fore:(.*)/</span>
       <span class="ruby-identifier">code</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;\e[#{get_color(:fore,$1.to_sym)}m&quot;</span>
       <span class="ruby-identifier">excel</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;:color =&gt; :#{$1}&quot;</span>
        <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">format</span>
          <span class="ruby-identifier">format</span>.<span class="ruby-identifier">font</span>.<span class="ruby-identifier">instance_variable_set</span> <span class="ruby-value str">&quot;@colors&quot;</span>, <span class="ruby-identifier">$1</span>.<span class="ruby-identifier">to_sym</span>
        <span class="ruby-keyword kw">end</span>
       <span class="ruby-comment cmt"># set foreground color to </span>
     <span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/back:(.*)/</span>
       <span class="ruby-identifier">code</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;\e[#{get_color(:back,$1.to_sym)}m&quot;</span>
       <span class="ruby-comment cmt"># set background color to </span>
    <span class="ruby-keyword kw">end</span>
  }
  <span class="ruby-identifier">code</span> = <span class="ruby-identifier">code</span>.<span class="ruby-identifier">join</span>
  <span class="ruby-identifier">code</span>
  <span class="ruby-identifier">excel</span> = <span class="ruby-identifier">excel</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;,&quot;</span>)
  <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">excel</span> <span class="ruby-operator">!=</span> [] <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">format</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span>
    <span class="ruby-identifier">excel</span> = <span class="ruby-identifier">eval</span>(<span class="ruby-node">&quot;Spreadsheet::Format.new(#{excel})&quot;</span>)
  <span class="ruby-keyword kw">end</span>
  <span class="ruby-identifier">excel</span> = <span class="ruby-identifier">format</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">format</span>
  [<span class="ruby-identifier">code</span>,<span class="ruby-identifier">excel</span>]
<span class="ruby-keyword kw">end</span></pre>
</body>
</html>